package com.daohang361.imqq.pugin.service;

import org.apache.mina.core.session.IoSession;

import com.daohang361.imqq.Asycore.Connector;
import com.daohang361.imqq.Asycore.QQUser;
import com.daohang361.imqq.ServerContex.SessionContex;
import com.daohang361.imqq.encoder.InterfaceEncoder;
import com.daohang361.imqq.hotLoader.PuginManager;
import com.daohang361.imqq.service.InterfaceService;

/** 
 * @author naner E-mail:likun3344@163.com 
 * @create time：2011-6-6 上午10:21:22 
 */
public class SendGroupImg implements InterfaceService {

	@Override
	public Object doService(Object... o) {
		QQUser myqq = SessionContex.getQQUser(Integer.parseInt( o[0]+""));
		Connector connector =SessionContex.getConnector(Integer.parseInt( o[0]+""));
		IoSession session=connector.getSession();
		InterfaceEncoder encoderD1 = ((InterfaceEncoder) PuginManager.GetPuginByKey("EncoderD1"));
		byte[] temp=null;
		byte[] hasSendD1=myqq.getAttr("imgKey");
		if(hasSendD1==null||hasSendD1.length==0)
		{
				
			 temp=encoderD1.encode(myqq, 0xd1, o);
			 myqq.setCommand(0xd1);
			 myqq.addDirectSendByte(temp);
			 session.write(myqq);
		}else{
			Connector Myconnector = new Connector();
			IoSession newSession = Myconnector.CreateSession("124.115.6.48", 8000);		
			InterfaceEncoder encoder88 = ((InterfaceEncoder) PuginManager.GetPuginByKey("Encoder88"));
			temp=encoder88.encode(myqq, 0x88, o);
			myqq.setCommand(0x88);
			myqq.addDirectSendByte(temp);
			newSession.write(myqq);
		}
		return null;
	}

	@Override
	public Object invoke(Object... o) {
		// TODO Auto-generated method stub
		return null;
	}

}
